﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using Cysharp.Threading.Tasks;
using Internal.KuiHuaBaoDian.Services.Guide;
using KuiHuaBaoDian.Services.Guide;

namespace KuiHuaBaoDian.Services.Guide {

    public interface IGuideStep {
    }

    public abstract class GuideStep : GuideEntity, IGuideStep, IGuideStepInternal {

        protected IReadOnlyList<GuideReference> ReferenceList;

        private IGuideSection m_Section;

        async UniTask IGuideStepInternal.Execute(IGuideSection section, IReadOnlyList<GuideReference> referenceList) {
            m_Section = section;
            ReferenceList = referenceList;
            await Execute();
        }

        protected IReadOnlyList<GuideReference> GetReference(string key) => m_Section.GetVariable(key);

        protected abstract UniTask Execute();

        Guid IGuideStepInternal.OutputTo => OutputTo;

        void IGuideStepInternal.Dispose() {
            Dispose();
            m_Section = null;
            ReferenceList = null;
        }
        protected abstract void Dispose();
    }
}

namespace Internal.KuiHuaBaoDian.Services.Guide {

    [EditorBrowsable(EditorBrowsableState.Never)]
    public interface IGuideStepInternal : IGuideStep {

        Guid OutputTo { get; }

        UniTask Execute(IGuideSection section, IReadOnlyList<GuideReference> referenceList);

        void Dispose();
    }
}
